<template>
  <div>
    <el-card shadow="never" class="aui-card--fill">
      <div class="crud__menu">
        <div class="crud__left">
          <el-form :inline="true">
            <el-form-item>
              <el-button type="primary" @click="uploadHandle()">{{ $t('oss.upload') }}</el-button>
            </el-form-item>
            <el-form-item>
              <el-button type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="crud__right">
          <el-button-group>
            <el-button icon="el-icon-refresh" @click="getDataList()"></el-button>
          </el-button-group>
        </div>
      </div>
      <div class="mod-oss__oss">
        <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle"
          @sort-change="dataListSortChangeHandle" style="width: 100%;">
          <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
          <el-table-column prop="url" :label="$t('oss.url')" header-align="center" align="left" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <a :href="scope.row.url" target="_blank">{{ scope.row.url }}</a>
            </template>
          </el-table-column>
          <el-table-column prop="createDate" :label="$t('oss.createDate')" sortable="custom" header-align="center"
            align="center" width="180"></el-table-column>
          <el-table-column :label="$t('handle')" header-align="center" align="center" width="80">
            <template slot-scope="scope">
              <el-button type="text" icon="el-icon-delete" size="small" @click="deleteHandle(scope.row.id)">{{
                $t('delete') }}</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
        </el-pagination>
        <!-- 弹窗, 上传文件 -->
        <upload v-if="uploadVisible" ref="upload" @refreshDataList="getDataList"></upload>
      </div>
    </el-card>
  </div>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import Upload from './oss-upload'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/sys/oss/page',
        getDataListIsPage: true,
        deleteURL: '/sys/oss',
        deleteIsBatch: true
      },
      dataForm: {},
      configVisible: false,
      uploadVisible: false
    }
  },
  components: {
    Upload
  },
  methods: {
    // 上传文件
    uploadHandle () {
      this.uploadVisible = true
      this.$nextTick(() => {
        this.$refs.upload.init()
      })
    }
  }
}
</script>
